const { ipcMain } = require("electron/main");

const handleRegisterIpcMain = (windowList) => {
    const { mainWindow } = windowList

    // 主进程到渲染进程(单向)
    mainWindow.on('ready-to-show', () => {
        mainWindow.webContents.send("mainToRenderer", "12");
    })


    // 渲染进程到主进程(单向)--1
    ipcMain.on("rendererToMainOne", (event, data) => {
        console.log("rendererToMainOne => ", data);
    });
    // 渲染进程到主进程(单向)--2
    ipcMain.handle("rendererToMainTwo", async (event, data) => {
        console.log("rendererToMainTwo => ", data);
    });


    // 渲染进程与主进程(双向)--1
    ipcMain.handle("rendererAndMainEachOtherOne", async (event, data) => {
        console.log("rendererAndMainEachOtherOne => ", data);
        if (data === '1212-2121') {
            return '1212-2121'
        }
    });
    // 渲染进程与主进程(双向)--2
    ipcMain.on("rendererAndMainEachOtherTwo", async (event, data) => {
        console.log("rendererAndMainEachOtherTwo => ", data);
        if (data === '1212-2121') {
            mainWindow.webContents.send("rendererAndMainEachOtherTwo", "1212-2121");
            // event.reply('rendererAndMainEachOtherTwo', '1212-2121')
        }
    });
};

const handleUnregisterIpcMain = () => {
    ipcMain.removeAllListeners([''])
    ipcMain.removeHandler('')
}

module.exports = {
    handleRegisterIpcMain,
    handleUnregisterIpcMain
}